package com.bamboocloud.dao;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.sql.ResultSet;
import java.sql.SQLException;

@Repository
public class UserSequenceDao {

    @Resource
    private JdbcTemplate template;

    public String getUserIdByUsername(String username){

        String sql = "select susr_id from tb_susr where susr_username = ? and susr_is_disabled = 0 and susr_is_deleted = 0";
        String name = template.queryForObject(sql, new RowMapper<String>() {
            @Override
            public String mapRow(ResultSet rs, int rowNum) throws SQLException {
                return rs.getString("permission_name");
            }
        }, username);
        return name;
    }

    public int updateUserSequence(String userId, Integer sequence){

        String sql = "update tb_susr_sorg set sequence = ? where susr_id = ? and isdeleted = 0";
        return template.update(sql, userId, sequence);
    }
}
